<template>
  <el-container class="container">
    <el-header class="header">
      <el-row>
        <el-col :span="8">
          <img src="../../assets/images/logo.png" alt>
        </el-col>
        <el-col :span="8">
          <h1>電商後台管理系統</h1>
        </el-col>
        <el-col :span="8" class="right">
          歡迎上海前端34星耀會員
          <a href="#" @click.prevent="startLogout">退出</a>
        </el-col>
      </el-row>
    </el-header>
    <el-container>
      <el-aside width="200px" class="aside">
        <el-menu
          :router="true"
          default-active="2-1"
          class="el-menu-vertical-demo"
          @open="handleOpen"
          @close="handleClose"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
        >
          <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>用戶管理</span>
            </template>
            <!-- <el-menu-item-group> -->
            <el-menu-item index="/users">用戶列表</el-menu-item>
            <!-- </el-menu-item-group> -->
          </el-submenu>
          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>权限管理</span>
            </template>
            <!-- <el-menu-item-group> -->
            <el-menu-item index="/roles">角色列表</el-menu-item>
            <el-menu-item index="/rights">权限列表</el-menu-item>
            <!-- </el-menu-item-group> -->
          </el-submenu>
          <el-submenu index="3">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>商品管理</span>
            </template>
            <!-- <el-menu-item-group> -->
            <el-menu-item index="3-1">商品列表</el-menu-item>
            <el-menu-item index="3-2">分類參數</el-menu-item>
            <el-menu-item index="3-3">商品分类</el-menu-item>
            <!-- </el-menu-item-group> -->
          </el-submenu>
          <el-submenu index="4">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>訂單管理</span>
            </template>
            <!-- <el-menu-item-group> -->
            <el-menu-item index="4-1">訂單列表</el-menu-item>
            <!-- </el-menu-item-group> -->
          </el-submenu>
          <el-submenu index="5">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>数据统计</span>
            </template>
            <!-- <el-menu-item-group> -->
            <el-menu-item index="5-1">數據報表</el-menu-item>
            <!-- </el-menu-item-group> -->
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main class="main">
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  methods: {
    // 退出功能
    async startLogout () {
      let res = await this.$confirm('此操作将永久退出賬戶, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
      console.log(res)

      // .then(() => {
      // 將本地的token清除掉
      localStorage.removeItem('token')
      // 跳轉login頁面
      this.$router.push('/login')
      this.$message({
        type: 'success',
        message: '退出成功!'
      })
        // })
        .catch(() => {
          this.$message({
            message: '已取消退出',
            type: 'info'
          })
        })
    }
  }
}
</script>

<style lang='less'>
* {
  margin: 0;
  padding: 0;
}

html,
body,
#app {
  height: 100%;
}
.container {
  height: 100%;
  min-width: 950px;
}
.el-header,
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
}
.el-header {
  text-align: left;
  padding: 0;
}
.header {
  background-color: #aec0d1;
  h1 {
    text-align: center;
    color: #fff;
    font-size: 28px;
  }
  .right {
    padding-right: 40px;
    text-align: right;
    a {
      color: #daa520;
    }
  }
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  line-height: 200px;
}
.aside {
  background-color: #525c64;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
</style>
